# -*- coding:utf-8 -*-
from __future__ import unicode_literals
import django.utils.timezone as timezone
from django.db import models
# Create your models here.

class deviceInfo(models.Model):
    info_id = models.AutoField(primary_key=True)
    info_to_device = models.ForeignKey('deviceManager', related_name='info_to_device_id')
    device_update_time = models.DateTimeField(auto_now=True)
    device_temperature = models.FloatField(null=False)
    device_light = models.FloatField(null=False)
    device_humidness = models.FloatField(null=False)

class deviceManager(models.Model):
    device_id = models.AutoField(primary_key=True)
    device_sn = models.CharField(max_length=30,unique=True,null=True)
    device_name = models.CharField(max_length=20, unique=True, null=False)
    device_location = models.CharField(max_length=32, unique=False, null=True)
    device_profile = models.CharField(max_length=30, null=True)
    device_status = models.BooleanField(default=False)
    is_delete = models.BooleanField(default=False)

    def __str__(self):
        if('True' == str(self.device_status)):
            self.device_status = 'online'
        else:
            self.device_status = 'offline'
        return '{'  + '\n' \
                    + '\t\t' + "\"device_id\"" + ': \"' + str(self.device_id) + '\"' + ',' + '\n' \
                    + '\t\t' + "\"device_name\"" + ': \"' + self.device_name + '\"' + ','  + '\n' \
                    + '\t\t' + "\"device_location\"" + ': \"' + str(self.device_location) + '\"' + ',' + '\n' \
                    + '\t\t' + "\"device_profile\"" + ': \"' + self.device_profile + '\"' + ',' + '\n' \
                    + '\t\t' + "\"device_status\"" + ': \"' + str(self.device_status) + '\"' + '\n' \
                    + '\t}'

# 需要执行的任务表
class taskTable(models.Model):
    task_id = models.AutoField(primary_key=True)
    task_to_device = models.ForeignKey('deviceManager', related_name='task_to_device_id')
    # Bask_mask = models.CharField(max_length=10,null=False, default='FFFF')
    wind_act = models.BooleanField(default=False)
    water_act = models.BooleanField(default=False)
    light_act = models.BooleanField(default=False)
    device_status = models.BooleanField(default=False)
    act_time = models.DateTimeField(null=False, default= timezone.now)
    task_isDone = models.BooleanField(default=False)
    task_isDel = models.BooleanField(default=False)
